﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using lumo.display.object2D;

namespace lumo.display.animation2D
{
    /// <summary>
    /// A position animation
    /// </summary>
    public class CircleAnimation2D : GenericAnimation2D<IPositionable2D>, IOriginable2D
    {
        // Private variables
        private Counter AngleCounter = new Counter();

        /// <summary>
        /// Constructor
        /// </summary>
        public CircleAnimation2D(Vector2 Origin, float Ray, float Time, IPositionable2D CurrentObject = null)
            : base(Time, Smooth.None, Loop.Reset, CurrentObject)
        {
            this.Origin = Origin;
            this.Ray = Ray;
        }

        /// <summary>
        /// Ray variable
        /// </summary>
        public float Ray { get; set; }

        /// <summary>
        /// Check if finished
        /// </summary>
        public override bool Finished { get { return (AngleCounter.Finished); } }

        /// <summary>
        /// Setup the values
        /// </summary>
        internal override void SetupValues()
        {
            AngleCounter.Reset(0, MathHelper.TwoPi, this.Time, this.Smoothness, this.LoopMode);
        }

        /// <summary>
        /// Update the values.
        /// </summary>
        /// <param name="Game">The game class</param>
        internal override void UpdateValues(LumoComponent Game)
        {
            AngleCounter.Update(Game);
            this.CurrentObject.Position = Origin + (new Vector2((float)Math.Cos(AngleCounter.Value) * Ray, (float)Math.Sin(AngleCounter.Value) * Ray));
        }

        #region IOriginable2D

        /// <summary> 
        /// Pivot point 
        /// </summary>
        public Vector2 Size { get { return Vector2.Zero; } }
        /// <summary> 
        /// Pivot point 
        /// </summary>
        private Vector2 _Origin = Vector2.Zero;
        /// <summary>
        /// Implemetation of Origin. IOriginable2D.
        /// </summary>
        public Vector2 Origin { get { return _Origin; } set { _Origin = value; } }
        /// <summary>
        /// Implementation of OX. IOriginable2D.
        /// </summary>
        public float OX { get { return _Origin.X; } set { _Origin.X = value; } }
        /// <summary>
        /// Implementation of OY. IOriginable2D.
        /// </summary>
        public float OY { get { return _Origin.Y; } set { _Origin.Y = value; } }

        #endregion
    }
}
